Also escape spaces in shell_escape
authorroot <root@localhost>
Mon, 4 May 2015 17:26:21 +0000 (19:26 +0200)
committerroot <root@localhost>
Tue, 2 Jun 2015 13:21:34 +0000 (15:21 +0200)
src/cargo/util/shell_escape.rs

index d02c1737fb5667b53f23a764a6b158601bb99479..39fb603bd39e18060873989fe82c57cbfb3ae577 100644 (file)
 
 use std::borrow::Cow;
 
-static SHELL_SPECIAL: &'static str = r#"\$'"`!"#;
+static SHELL_SPECIAL: &'static str = r#" \$'"`!"#;
 
-/// Escape characters that may have special meaning in a shell.
+/// Escape characters that may have special meaning in a shell,
+/// including spaces.
 pub fn shell_escape(s: Cow<str>) -> Cow<str> {
     let escape_char = '\\';
     // check if string needs to be escaped
@@ -32,9 +33,11 @@ pub fn shell_escape(s: Cow<str>) -> Cow<str> {
 
 #[test]
 fn test_shell_escape() {
-    assert_eq!(shell_escape("--aaa=bbb ccc".into()), "--aaa=bbb ccc");
+    assert_eq!(shell_escape("--aaa=bbb-ccc".into()), "--aaa=bbb-ccc");
+    assert_eq!(shell_escape("linker=gcc -L/foo -Wl,bar".into()),
+                            r#"linker=gcc\ -L/foo\ -Wl,bar"#);
     assert_eq!(shell_escape(r#"--features="default""#.into()),
                             r#"--features=\"default\""#);
-    assert_eq!(shell_escape(r#"'!\$` \\ \n"#.into()),
-                            r#"\'\!\\\$\` \\\\ \\n"#);
+    assert_eq!(shell_escape(r#"'!\$`\\\n "#.into()),
+                            r#"\'\!\\\$\`\\\\\\n\ "#);
 }